package interfaceComUsuario;

import java.awt.Cursor;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragSource;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import acessorios.Carta;
import acessorios.RolagemDeadlands;

public class LabelCarta extends JLabel implements DragGestureListener
{
	/**
	 * 
	 */
	private static final long serialVersionUID = -113751801320234463L;
	private Carta carta;
	private RolagemDeadlands rolagemDeadlands;

	public LabelCarta()
	{
		this("", null, null, null);
	}

	public LabelCarta(String text, JTextField textFieldAssociado, JLabel labelAssociado, JPanel panelAssociado)
	{
		super(text);
		carta = null;
		new DropTargetListner(this, textFieldAssociado, labelAssociado, panelAssociado);
		
		DragSource ds = new DragSource();
		ds.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_MOVE, this);
	}

	/**
	 * @return the carta
	 */
	public Carta getCarta()
	{
		return this.carta;
	}

	/**
	 * @param carta the carta to set
	 */
	public void setCarta(Carta carta)
	{
		this.carta = carta;
		this.setText(carta.toString());
	}

	@Override
	public void dragGestureRecognized(DragGestureEvent dge)
	{
		Cursor cursor = null;
		
		if(dge.getDragAction() == DnDConstants.ACTION_MOVE)
		{
			cursor = DragSource.DefaultMoveDrop;
		}
		dge.startDrag(cursor, new Carta(this.carta.consultarValor(), this.carta.consultarNaipe()));
		this.setText("");
	}

	/**
	 * @return the rolagemDeadlands
	 */
	public RolagemDeadlands getRolagemDeadlands()
	{
		return this.rolagemDeadlands;
	}

	/**
	 * @param rolagemDeadlands the rolagemDeadlands to set
	 */
	public void setRolagemDeadlands(RolagemDeadlands rolagemDeadlands)
	{
		this.rolagemDeadlands = rolagemDeadlands;
	}
	
}
